package com.lnsf.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lnsf.dao.CommentsDao;
import com.lnsf.dao.UserDao;
import com.lnsf.entity.Comments;
import com.lnsf.entity.User;
import com.lnsf.service.ICommentService;
import com.lnsf.service.IUserService;

/*
 * UserService 实现类UserServiceImpl
 * author:黄华炎
 * 2017-07-26
 * 
 * 
 */

@Service
@Transactional
public class CommentsServiceImpl implements ICommentService {

	@Autowired
	private CommentsDao commentsDao;

	
	/*保存评论
	*从上一层评论拿到一个parent，如果为Null, 则是第一层评论
	*如果不为空，则是回复上一层的
	*/
	@Override
	public void saveComm(Comments comments) {
		commentsDao.save(comments);
		
		
	}

	//获取个人的评论,通过用户id，商品id
	@Override
	public List<Comments> findCommByUserAndGood(Comments comments) {
		//int userid = comments.getUser().getId();
		int goodid = comments.getGoods().getId();
		//int commnetsId = comments.getCommnetsId();
		
		List<Comments> list = commentsDao.findCommByUserAndGood(goodid);
		
		return list;
	}

	@Override
	public Comments findCommById(Integer commId) {
		return commentsDao.findOne(commId);
		
	}

	//配合保存评论，修改parent值
	@Override
	public int updateCom(int preCommId, Comments currentComments) {
		int currentCommId = currentComments.getCommnetsId();
		int i = commentsDao.updateComm(preCommId, currentCommId);	
		return i;
	}
	
	
	

	
	
	
	
	
	
}
